<?php

/**
 * 花集通京东退款API(为了方便视图呈现，重新调整数据层级等)
 *
 * @author cjj
 */
class PopAPI {
    private $_client;

    /**
     * Constructor
     */
    public function __construct($options=array()) {
        $client = isset($options[0]) ? $options[0] : null;
        if (!$client || !$client instanceof JDClient) {
            throw new APIException(30017);
        }
        $this->_client = $client;
    }

    /**
     * 根据商品ID列表，获取商品列表
     *
     * @param integer $page
     * @param integer $page_size
     * @param array $params
     *
     * @return mixed|null
     * @throws APIException
     */
    public function afsRefundApplyQueryList($page,$page_size,$params=array()) {
        if(!$page||!$page_size){
            return null;
        }
        $paras = array(
            'page_index'=>$page,
            'page_size'=>$page_size
        );
        $paras=array_merge($paras,$params);
        $result=$this->_client->api('jingdong.pop.afs.refundapply.querylist', $paras);
        $response=isset($result['jingdong_pop_afs_refundapply_querylist_responce'])?$result['jingdong_pop_afs_refundapply_querylist_responce']:array();
        $refundApplyResponse=isset($response['refundApplyResponse'])?$response['refundApplyResponse']:array();
        $total=isset($refundApplyResponse['count'])?$refundApplyResponse['count']:0;
        $refundApplyResponse=isset($refundApplyResponse['result_state'])&&$refundApplyResponse['result_state']?$refundApplyResponse:null;
        if(!$refundApplyResponse){
            return null;
        }
        $refunds=isset($refundApplyResponse['results'])?$refundApplyResponse['results']:array();
        $data=array(
            'total_records'=>$total,
            'data'=>array('refunds'=>$refunds)
        );
        return $data;
    }
}